package com.competition.front.controller;


import com.competition.commonutils.R;
import com.competition.front.entity.ModulePicture;
import com.competition.front.service.ModulePictureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 富文本编辑器图片路径 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/front/module-picture")
@CrossOrigin
@Api(description = "关于模块（富文本编辑器）的图片相关的接口")
public class ModulePictureController {

    @Autowired
    private ModulePictureService modulePictureService;
    @GetMapping("getByModulePictureId/{moduleId}")
    @ApiOperation("根据模块id获取该模块所有的图片地址")
    public R getByModulePictureId(@PathVariable String moduleId){
        return R.ok().data("modulePictures",modulePictureService.queryByModuleId(moduleId));
    }
    @PostMapping("addByModuleId/{moduleId}")
    @ApiOperation("输入模块id及对应的图片地址，保存到数据库")
    public R addByModuleId(@RequestBody List<ModulePicture> modulePictures, @PathVariable String moduleId){
        for (ModulePicture modulePicture : modulePictures) {
            modulePicture.setModuleId(moduleId);
        }
        modulePictureService.saveBatch(modulePictures);
        return R.ok();
    }

}

